home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / GMS / GMSDev / Source / C / IceBreaker / IceBreaker.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-12-14  |  5.3 KB  |  187 lines

  1. /*
  2. ** Name:      Ice-Breaker
  3. ** Version:   1.1
  4. ** Author:    Paul Manias
  5. ** Date:      December 1997.
  6. ** Copyright: DreamWorld Productions 1997.
  7. ** Compile:   sc IceBreaker.c nolink
  8. **            PhxAss /IceAssembler.asm
  9. **            slink FROM lib:c.o,IceBreaker.o,/IceAssembler.o TO IceBreakerCon LIBRARY LIB:sc.lib,LIB:Amiga.lib
  10. **
  11. ** This is the entry code for IceBreaker, it sets things up so that the assembler
  12. ** code is ready to intercept debug messages.
  13. **
  14. */
  15.  
  16. #include <proto/dpkernel.h>
  17. #include <system/debug.h>
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/gmsdos.h>
  21. #include <dos/dos.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25.  
  26. extern struct ExecBase    *SysBase;
  27. extern far struct GFXBase *GFXBase;
  28.  
  29. #define LVODEBUGMESSAGE -378
  30. #define LVOERRORMESSAGE -384
  31. #define LVOSTEPBACK     -390
  32. #define LVODPRINTF      -270
  33.  
  34. extern far WORD maxstep;
  35. extern ULONG libDebugMessage(void);
  36. extern ULONG libErrorMessage(void);
  37. extern ULONG libStepBack(void);
  38. __asm __saveds ULONG libDPrintF(register __a5 LONG *);
  39.  
  40. BYTE dbgstr[512];
  41.  
  42. struct Task *maintask;
  43. struct Task *edittask = NULL;
  44.  
  45. BPTR conhandle=0;      /* Handle to output debug information */
  46.  
  47. void mainroutine(void);
  48. long getlen(char string[]);
  49. void wtext(char string[]);
  50. BPTR openconsole(void);
  51. void PrintUsage(void);
  52.  
  53. /***********************************************************************************
  54. ** Usage: IceBreaker [MAXSTEP n]
  55. **
  56. **
  57. ** ArgV: 0   = IceBreaker
  58. **       1 - = Arguments
  59. */
  60.  
  61. LONG main(LONG argc, BYTE *argv[])
  62. {
  63.    void *oldDebugMessage;
  64.    void *oldErrorMessage;
  65.    void *oldStepBack;
  66.    void *oldDPrintF;
  67.  
  68.    if (argc > 1) {
  69.       if (argv[1][0] IS '?') {
  70.          PrintUsage();
  71.          return(NULL);
  72.       }
  73.       if (argc > 2) {
  74.          if (stricmp(argv[1], "MAXSTEP") IS NULL) {
  75.             maxstep = atoi(argv[2]);
  76.          }
  77.          else printf("Unknown argument %s.\n",argv[1]);
  78.       }
  79.    }
  80.  
  81.    if (maxstep <= NULL) maxstep = 2;
  82.  
  83.    dosDelay(5);
  84.  
  85.    maintask = FindTask(NULL);
  86.  
  87.    if (DPKBase = (struct DPKBase *) OpenLibrary("GMS:libs/dpkernel.library",0)) {
  88.       if (DebugActive() IS ERR_OK) {
  89.          if (GFXBase = (struct GFXBase *) OpenLibrary("graphics.library",0)) {
  90.             if (conhandle = dosOutput()) {
  91.                Forbid();
  92.                oldDebugMessage = SetFunction((struct Library *)DPKBase,LVODEBUGMESSAGE,&libDebugMessage);
  93.                oldErrorMessage = SetFunction((struct Library *)DPKBase,LVOERRORMESSAGE,&libErrorMessage);
  94.                oldStepBack     = SetFunction((struct Library *)DPKBase,LVOSTEPBACK,&libStepBack);
  95.                oldDPrintF      = SetFunction((struct Library *)DPKBase,LVODPRINTF,&libDPrintF);
  96.                SumLibrary((struct Library *)DPKBase);
  97.                Permit();
  98.  
  99.                mainroutine();
  100.  
  101.                Forbid();
  102.                SetFunction((struct Library *)DPKBase,LVODEBUGMESSAGE,oldDebugMessage);
  103.                SetFunction((struct Library *)DPKBase,LVOERRORMESSAGE,oldErrorMessage);
  104.                SetFunction((struct Library *)DPKBase,LVOSTEPBACK,oldStepBack);
  105.                SetFunction((struct Library *)DPKBase,LVODPRINTF,oldDPrintF);
  106.                SumLibrary((struct Library *)DPKBase);
  107.                Permit();
  108.             }
  109.             else printf("Could not find output handle.");
  110.             CloseLibrary((struct Library *)GFXBase);
  111.          }
  112.          else printf("Could not open graphics.library");
  113.          DebugInactive();
  114.       }
  115.       else printf("Debug initialisation failed.");
  116.       CloseLibrary((struct Library *)DPKBase);
  117.    }
  118.    else printf("Could not open dpkernel.library.");
  119.  
  120.    return(NULL);
  121. }
  122.  
  123. /***********************************************************************************/
  124.  
  125. void PrintUsage(void)
  126. {
  127.   printf("\n");
  128.   printf("This program will wait until a program using GMS is executed.  Any\n");
  129.   printf("debug messages that are sent while it is active will be intercepted\n");
  130.   printf("and printed out to this window.\n\n");
  131.   printf("Usage: IceBreaker [MAXSTEP n]\n\n");
  132. }
  133.  
  134. /*********************************** MAIN LOOP *************************************/
  135.  
  136. void mainroutine(void)
  137. {
  138.   LONG result;
  139.  
  140.   wtext("\n");
  141.   wtext("This program will wait until a program using GMS is executed.  Any\n");
  142.   wtext("debug messages that are sent while it is active will be intercepted\n");
  143.   wtext("and printed out to this window.\n\n");
  144.   wtext("Press CTRL-C at any time to exit.\n\n");
  145.   wtext("Type                 | Data\n");
  146.   wtext("---------------------+---------------------------------------------\n");
  147.  
  148.   do {
  149.      result = Wait(SIGBREAKF_CTRL_C);
  150.   } while (!(result & SIGBREAKF_CTRL_C));
  151.  
  152.   wtext("");
  153. }
  154.  
  155. /***********************************************************************************/
  156.  
  157. void wtext(char string[]) {
  158.   dosWrite(conhandle,(ULONG)string,getlen(string));
  159. }
  160.  
  161. /***********************************************************************************/
  162.  
  163. long getlen(char string[]) {
  164.   WORD length = NULL;
  165.  
  166.   while (string[length] != 0) {
  167.     length++;
  168.     if (length > 256) break;
  169.   }
  170.   return(length);
  171. }
  172.  
  173. /***********************************************************************************/
  174.  
  175. __asm __saveds ULONG libDPrintF(register __a5 LONG *array)
  176. {
  177.   if (array != NULL) {
  178.      sprintf(dbgstr,(BYTE *)array[0],array[1],array[2],array[3],array[4]);
  179.      DMsg(dbgstr);
  180.   }
  181.   else {
  182.      DMsg("No arguments supplied to DPrintF().");
  183.   }
  184.   return(NULL);
  185. }
  186.  
  187.